package com.dm0858.bianmin.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;

import com.alibaba.fastjson.JSON;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.databinding.ActivityLivingPaymentBinding;
import com.dm0858.bianmin.databinding.ActivityPlatformConstructionLayoutBinding;
import com.dm0858.bianmin.mine.base.BaseActivity;
import com.dm0858.bianmin.mine.bean.PlatformConstructionBeanData;
import com.dm0858.bianmin.mine.model.MineModel;
import com.dm0858.bianmin.mine.network.Retrofit;

/**
 * @author 迪迪丶Sir
 * @description 生活缴费
 * @e-mail asd969709719@qq.com
 * @since 2020-05-24
 **/
public class LivingPaymentActivity extends BaseActivity implements View.OnClickListener{

    private ActivityLivingPaymentBinding binding;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_living_payment);
        binding.setOnClick(this);
        initData();
    }

    @Override
    protected void initData() {
        WebSettings webSettings = binding.webView.getSettings();
        //允许使用js
        webSettings.setJavaScriptEnabled(true);
        //不支持屏幕缩放
        webSettings.setSupportZoom(false);
        webSettings.setBuiltInZoomControls(false);
        //不显示webview缩放按钮
        webSettings.setDisplayZoomControls(false);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口，如window.open()，默认为false
        webSettings.setJavaScriptEnabled(true);//是否允许JavaScript脚本运行，默认为false。设置true时，会提醒可能造成XSS漏洞
        webSettings.setSupportZoom(true);//是否可以缩放，默认true
        webSettings.setBuiltInZoomControls(true);//是否显示缩放按钮，默认false
        webSettings.setUseWideViewPort(true);//设置此属性，可任意比例缩放。大视图模式
        webSettings.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
        webSettings.setAppCacheEnabled(true);//是否使用缓存
        webSettings.setDomStorageEnabled(true);//开启本地DOM存储
        webSettings.setLoadsImagesAutomatically(true); // 加载图片
        webSettings.setMediaPlaybackRequiresUserGesture(false);//播放音频，多媒体需要用户手动？设置为false为可自动播放
        binding.webView.setWebViewClient(new WebViewClient());
        binding.webView.loadUrl("http://life.ccb.com/cn/paymentv3/mobilev3/indexv3.html");
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                onBackPressed();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && binding.webView.canGoBack()) {
            binding.webView.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}